import pagination from '@/views/pagination'  //分页组件

import agentHttp from '@/utils/agentHttp.js'
import {debounce,initDataTime,timestampToTime} from '@/utils/index.js'
import LookBill from './Popup/LookBill';        //查看审核单
import AddOrCompileBill from './Popup/AddOrCompileBill'; //添加或者编辑单子
import AuditBill from './Popup/AuditBill';   //审核单子

export default {
  name: 'priceAudit',
  created(){
   this.seachData()
  },
  components:{
    LookBill,AddOrCompileBill,AuditBill,pagination
  },
  data() {
  	return {
      //搜索字段
  		searchForm:{
  			dealerName:"",
        orderNumber:"",
        startDate:"",
        endDate:"",
        carOrderStatus:'',//selsct表单的选择
      },
      //表格字段
      tableData: [],
      userType:'',        //0是链上车，1是资金方，2是SPV，3是链上车SPV
      carOrderStatusMap:null,   //状态管理
      id:null,
      //发送给弹窗的数据
      dialogSendData:{
        isAdd:true,                //是否为编辑或者新增  true是   false否
        dialogFormVisible:false,   //弹窗是否显示        true是   false否

      },
      startDateOpt: {
        disabledDate(time) {
          return time.getTime() > Date.now() 
        }
      },
      endDateOpt:{
        disabledDate:(time)=>{
          return  time.getTime()< new Date(this.searchForm.startDate).getTime();
        }
      },
      resetFormStatus:false,
      buttonValue:'' ,      //通过按钮能容判断显示那个菜单   
     look_bill_state:'默认',  //通过状态来显示查看菜单的子菜单
     carOrderId:'',   //传给子组件的id
  	}
  },

  methods: {
    seachData(){        //获取数据
        var params=initDataTime(this.searchForm)||{};
        params.page = this.tableData.page || 1;
        params.rows = this.tableData.rows || 10;
        agentHttp.get('adminApi/admin/mortgage_order_remit/list',params ).then((data)=>{
          if (data.success) {
              this.tableData = data.data.tableData;
              this.carOrderStatusMap = data.data.carOrderStatusMap
              this.userType = data.data.userType ;     
            }
        })
      },
    formIsEdit(e){       //点击按钮，表单是否添加还是查看
       let value = e.currentTarget.innerText ;
       this.carOrderId =  e.currentTarget.dataset.carorderid   //给子组件的id
       this.dialogSendData.dialogFormVisible=true;   
       this.buttonValue = value ;  

       if(value==='添加'){  //可编辑
        this.dialogSendData.isAdd=false;
       }else if(value==='查看'){           //不可被编辑
        this.dialogSendData.isAdd=true;
       }else if(value==='child查看'){
        this.dialogSendData.isAdd=true;
       }

    },
    setChildCode(obj){   //子组件发射上来的事件，显示不同的子组件
      this.buttonValue = obj.value
      this.id = obj.id ;
      switch(this.buttonValue){
            case 'child编辑':
            this.dialogSendData.isAdd=false;
            break ;
            case 'child审核':
            this.dialogSendData.isAdd=false;
            break ;
            case 'child查看':
            this.dialogSendData.isAdd=true;
            break ;
          defalut:
            break ;
      }
  
    },
    getDate(time){
        return timestampToTime(time)
    },
    resetSearchForm(formName){
      this.$refs[formName].resetFields();
      this.seachData()
    },
    debounceSeach(){
     
      this.tableData.page=1;
      debounce(this.seachData(this.searchForm),1000)
    },
  }
}